(function() {
  var Commodity, commodityHandle, noop, verify, _;

  _ = require('underscore');

  Commodity = require('./mongoose_client').Commodity;

  noop = function() {};

  commodityHandle = {
    save: function(data, cbf) {
      cbf = cbf || noop;
      if (verify(data, cbf)) {
        return new Commodity(data).save(function(err) {
          return cbf(err);
        });
      }
    },
    count: function(query, cbf) {
      cbf = cbf || noop;
      return Commodity.count(query, cbf);
    },
    findAll: function(cbf) {
      cbf = cbf || noop;
      return Commodity.find({
        sort: '_id'
      }, cbf);
    },
    find: function(query, options, cbf) {
      cbf = cbf || noop;
      return Commodity.find(query, null, options, cbf);
    },
    findByIdAndUpdate: function(id, update, cbf) {
      cbf = cbf || noop;
      return Commodity.findByIdAndUpdate(id, update, cbf);
    }
  };

  verify = function(data, cbf) {
    if (_.isObject(data)) {
      return true;
    } else {
      cbf(new Error('the save data is not a objcet'));
      return false;
    }
  };

  module.exports = commodityHandle;

}).call(this);
